$(function() {
	$('#getConfigList').click(function() {
		getConfigList();
	});
	
	$('#resetConfig').click(function() {
		resetConfig();
	});
});
var configHisList;
function getConfigList() {
	configHisList = new Array();
	$.ajax({
		url : '/Log4jControlWeb/GetConfigList',
		data : {
			operatepwd : "DEFAULT"
		},
		cache : false,
		dataType : 'json',
		error : function() {
			window.location.href = "error.html";
		},
		success : function(data) {
			if (data != null && data.length > 0) {
				var html = '';
				for (var i = 0; i < data.length; i++) {
					configHisList.push(data[i]);
					html += makeRadioHtml(data[i], i);
				}
				$('#configHisList').html(html)
			}
		}
	});
}
function makeRadioHtml(oConfigHis, index) {
	return "<p><input name=\"configHisRadio\" type=\"radio\"  value = '" + oConfigHis.configCode
			+ "' onclick = 'showConfigStr(" + index + ")' /><span class = 'configCode'>" + oConfigHis.configCode + "</span></p>"
}

function resetConfig() {
	var configcode = $('input:radio[name="configHisRadio"]:checked').val();
	if (configcode != '' && configcode != null) {
		$.ajax({
			url : '/Log4jControlWeb/ResetConfig',
			data : {
				operatepwd : "DEFAULT",
				configcode : configcode
			},
			cache : false,
			dataType : 'json',
			error : function() {
				window.location.href = "error.html";
			},
			success : function(data) {
				getConfigList();
			}
		});
	}
}

function showConfigStr(index){
	$('#configText').val(configHisList[index].context)
}
